<?php $CDN= $this->CommonHelper()->imageDomain();?>
<body class="app" data-ad="true">
<section class="app-content">
	<section class="page page-index noline" data-plugin-type="info_front">
        <div class="swiper-banner">
            <ul class="swiper-wrapper">
            <?php if ($this->bannerList):?>
			<?php foreach ($this->bannerList as $v):?>
                <li class="swiper-slide"><a href="<?php echo $v['url'];?>"><img src="<?php echo "{$CDN}{$v['image']}";?>"></a></li>
            <?php endforeach; ?>
            <?php endif;?>    
            </ul>
            <div class="pagination-banner"></div>
        </div>
        <div class="search-top">
            <select id="catalog-type">
                <option value="0">全部</option>
                <?php if ($this->catalogList):?>
                <?php  $type = $_GET['type']; ?>
				<?php foreach ($this->catalogList as $v):?>
					<?php if($v['catalog_id']==$type){
						$selected= "selected='selected'";
					}else{
						$selected="";
					}
					?>
					<option <?php echo $selected; ?> value="<?php echo $v['catalog_id'];?>"><?php echo $v['catalog_name'];?></option>
			 	<?php endforeach; ?>
            	<?php endif;?> 
                
            </select>
            <a class="search-link" href="/index/search">请输入商家或店铺名称</a>
        </div>
        <div class="category">
            <ul>
            <?php if ($this->types):?>
			<?php foreach ($this->types as $v):?>
                <li><a href="<?php echo $v['type_link'];?>"><img src="<?php echo  "{$CDN}{$v['type_thumb_image']}";?>"/><?php echo $v['type_name'];?></a></li>
            <?php endforeach; ?>
            <?php endif;?> 
            </ul>
        </div>
        <div class="item-list mt20">
        	<?php if ($this->orgRecommends):?>
			<?php foreach ($this->orgRecommends as $v):?>
			<?php 
				if($v['data']['org_type']==1){//商户
					$url=$this->url('organization', array('action'=>'vMerchant','id'=> $v['data']['org_id']));
				}else{//商城
					$url=$this->url('organization', array('action'=>'index','id'=> $v['data']['org_id']));
				}
				
			?>
            <dl>
                <dt><img src='<?php echo "{$CDN}{$v['data']['org_thumb_image']}" ?>'/></dt>
                <dd>
                    <h3 class="title_s"><a href="<?php echo $url;?>" ><?php echo $v['data']['org_name'] ?></a></h3>
                    <div class="recommend">推荐商品/菜品：
                    	<?php  foreach($v['recommended'] as $k1=>$v1):?>
                    	<span><?php echo $v1;?></span>
                    	<?php endforeach;?>
                        <a class="ico-arr ico-down"></a>
                    </div>
                    <a class="ico-arr ico-right" href="<?php echo $url; ?>"></a>
                    
                </dd>
            </dl>
            <?php endforeach;?>
            <?php endif;?> 
        </div>
	</section>
	<?php echo $this->partial('public/menu.phtml'); ?>
</section>

<script type="text/javascript">
    var type="<?php echo $_GET['type']; ?>";
	String.format=function(){
	    if(arguments.length==0){
	        return null;
	    }
	   if (arguments.length > 1) { 
	       for (var i = 1; i < arguments.length; i++) {
	           if (arguments[i] != undefined) {
	               var reg= new RegExp("\\%" + i + "\\$s", "gm");
	               arguments[0] = arguments[0].replace(reg, arguments[i]);
	           }
	       }
	   }
	   return arguments[0];
	}
	
	$("#catalog-type").change(function(){
		var reg= new RegExp("type=[0-9]+", "gm");
		var crrtHref=document.location.href; 
		var rs=crrtHref;
		var _val =$("#catalog-type").val();
		//检查是否有type字段
		if(reg.test(crrtHref)){
			if(_val>0){
				rs = crrtHref.replace(reg,"type="+_val);
			}else{
				rs = "http://"+window.location.host;
			}
		}else{
			if(_val>0){
				rs=String.format(crrtHref+"?type=%1$s",_val);
			}else{
				rs=crrtHref;
			}
		}
		document.location.href = rs;
	});
	
	//$(function(){
	//	$('#catalog-type [value="'+type+'"]').attr("selected","selected");
	//})
	
</script>
